package com.hand.demo.app.service.impl;

import io.choerodon.core.domain.Page;
import io.choerodon.mybatis.pagehelper.PageHelper;
import io.choerodon.mybatis.pagehelper.domain.PageRequest;
import org.springframework.beans.factory.annotation.Autowired;
import com.hand.demo.app.service.HhrTaLangService;
import org.springframework.stereotype.Service;
import com.hand.demo.domain.entity.HhrTaLang;
import com.hand.demo.domain.repository.HhrTaLangRepository;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 语言证书表(HhrTaLang)应用服务
 *
 * @author
 * @since 2025-06-16 12:16:53
 */
@Service
public class HhrTaLangServiceImpl implements HhrTaLangService {
    @Autowired
    private HhrTaLangRepository hhrTaLangRepository;

    @Override
    public Page<HhrTaLang> selectList(PageRequest pageRequest, HhrTaLang hhrTaLang) {
        return PageHelper.doPageAndSort(pageRequest, () -> hhrTaLangRepository.selectList(hhrTaLang));
    }

    @Override
    public void saveData(List<HhrTaLang> hhrTaLangs) {
        List<HhrTaLang> insertList = hhrTaLangs.stream().filter(line -> line.getId() == null).collect(Collectors.toList());
        List<HhrTaLang> updateList = hhrTaLangs.stream().filter(line -> line.getId() != null).collect(Collectors.toList());
        hhrTaLangRepository.batchInsertSelective(insertList);
        hhrTaLangRepository.batchUpdateByPrimaryKeySelective(updateList);
    }

    @Override
    public void deleteByResumeId(Long resumeId) {
            HhrTaLang query = new HhrTaLang();
            query.setResumeId(resumeId);
            List<HhrTaLang> existingList = hhrTaLangRepository.selectList(query);
            if (!existingList.isEmpty()) {
                hhrTaLangRepository.batchDeleteByPrimaryKey(existingList);
            }
    }
}

